#include <iostream>
#include <cstring>

#include "DataSaver.h"
#include "DBHelper.h"

DataSaver::DataSaver(){
	m_tag = 0;
	m_value = 0;
	m_tick = 0;
	memset(m_devId, 0 ,sizeof(m_devId));
}

DataSaver::~DataSaver(){
}

void DataSaver::init(dataPackage* s, unsigned char* devId) {
	memset(m_devId, 0, sizeof(m_devId));
	
	m_tag = s->getTagValue();
	m_value = s->getValue();
	m_tick = s->getTickValue();
	//strcpy_s((char*)m_devId, sizeof(m_devId), (char*)devId);
	memcpy_s((char*)m_devId, sizeof(m_devId), (char*)devId, sizeof(m_devId));

	saveRecode();
}

bool DataSaver::saveRecode() {
	DBhelper::getIt()->writeToDB(m_tick, m_tag, m_value, m_devId);

	return true;
}